﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;

namespace QiHe
{
    public partial class Task_List : Form
    {
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
       
        DataSet TSKList;
        int tc;
        DataSet ts;
        public Task_List()
        {
            InitializeComponent();
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }

        private void Task_List_Load(object sender, EventArgs e)
        {
            if (IsConnectInternet())
            {
                DBS sop = new DBS();
                TSKList = sop.RPlist_UnFinish();

                DataSet ts = TSKList.Copy();
                ts.Tables[0].Columns.Add(" 报修时间 ");
                ts.Tables[0].Columns.Add(" 报修设备 ");
                ts.Tables[0].Columns.Add(" 审批意见 ");
                ts.Tables[0].Columns.Add(" 审批人 ");
                ts.Tables[0].Columns.Add(" 报修科室 ");
                ts.Tables[0].Columns.Add(" 报修人 ");
                ts.Tables[0].Columns.Add(" 维修进程 ");
                ts.Tables[0].Columns.Add(" 工程师 ");
                ts.Tables[0].Columns.Add(" 故障描述 ");





                ts.AcceptChanges();
                dataGridView1.DataSource = ts.Tables[0];
                tc = ts.Tables[0].Rows.Count;
            }
           
           
        }

        private void 维修中ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EQ_List ts = new EQ_List();
            ts.Show();
        }

        private void 任务列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Task_List ts = new Task_List();
            ts.Show();
        }

        private void 添加设备ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEQ add = new AddEQ();
            add.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (IsConnectInternet())
            {

                if (lable1.Text.Equals("等待回应的任务"))
                {
                    lable1.Text = "执行中的任务";
                    DBS sop = new DBS();
                    TSKList = sop.RPlist_UnFinish();
                    dataGridView1.DataSource = TSKList.Tables[0];
                   /* if (tc < TSKList.Tables[0].Rows.Count)
                    {

                        System.Media.SystemSounds.Asterisk.Play();
                        System.Media.SystemSounds.Asterisk.Play();
                        System.Media.SystemSounds.Asterisk.Play();



                    }
                    * */
                    tc = TSKList.Tables[0].Rows.Count;
                }
                else
                {

                    lable1.Text = "等待回应的任务";
                    DBS sop = new DBS();
                    TSKList = sop.RPlist_Unreply();
                    dataGridView1.DataSource = TSKList.Tables[0];
                   
                    tc = TSKList.Tables[0].Rows.Count;
                
                }
            }
            else
            MessageBox.Show("请检查网络！");

        }

        private void 用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void 添加用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_User_Tech ts = new Add_User_Tech();
            ts.Show();
        }

        private void 部门编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Depts_Edit ts = new Depts_Edit();
            ts.Show();
        }

        private void 维修任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 添加工程师ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add_EGN ts = new Add_EGN();
            ts.Show();
        }

        private void 批量添加设备ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEQ ts = new AddEQ();
            ts.Show();
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Task.CallTime = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][6].ToString();
            Task.Dept = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][0].ToString() + " " + TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
            Task.CallUser = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
            Task.Content = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][8].ToString();
            Task.State = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
            Task.EGN = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
            Task.Flag = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][7].ToString();
            Task.EQName = TSKList.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();

            TaskInfo ti = new TaskInfo();
            ti.ShowDialog();
            this.Refresh();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

           
        }

        private void 历史任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Task_Edit ts = new Task_Edit();
            ts.ShowDialog();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            this.Close();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

          
        }

        private void 添加任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Add_Task ts = new Add_Task("000000");
            ts.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Add_Task ts = new Add_Task("000000");
            ts.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Task_Edit ts = new Task_Edit();
            ts.ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Depts_Edit ts = new Depts_Edit();
            ts.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            EQ_List ts = new EQ_List();
            ts.Show();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {

        }
        public static bool IsConnectInternet()
        {
            int Description = 0;
            return InternetGetConnectedState(Description, 0);
        }
    }
}
